import user from '../../utils/user.js'
import {
    getProjectList,
    putLeftDelete
} from '../../api/app.js'
import {
    toast
} from '../../utils/util'
Page({
    data: {
        projectList: []
    },
    async onLoad(){
        if (!user.userId) {
            return 0
        }
        const projectList = await getProjectList({
            id: user.userId
        })
        this.setData({
            projectList
        })
        projectList.forEach((item,index)=>{
            let date =  new Date(item.createTime.replace(/-/g,'/'))
            this.setData({
                ['projectList[' + index + '].createTime'] : date.getFullYear()+'年'+(date.getMonth() +1 <10 ?'0' + (date.getMonth() +1) : date.getMonth() +1) +'月' + date.getDate() +'日'
            })
        })
    },
    async onDisplay(event){
        let {isleave,projectid,recordid,type} = event.currentTarget.dataset
        if(isleave === 0){
            await putLeftDelete({
                id:recordid,
                isShow:'1'
            })
            wx.navigateTo({
                url: '../../pages/detail/detail?id=' + projectid + '&type=' + type
            })
        }else{
            toast('您已离职')
        }
    }
})
